package com.animallife.android.ui;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;

import com.animallife.android.R;
import com.animallife.android.db.AnimalColumns;
import com.animallife.android.model.Animals;
import com.animallife.android.util.Config;
import com.flurry.android.FlurryAgent;

public class SplashScreenActivity extends Activity {
	private static final long SPLASH_DISPLAY_LENGTH = 1500;

	public void onStart() {
		super.onStart();
		FlurryAgent.onStartSession(this, "CJVA21QV9JQKNUQS93F9");
	}

	public void onStop() {
		super.onStop();
		FlurryAgent.onEndSession(this);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);

		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
		boolean isEnable = prefs.getBoolean(Config.IS_ENABLE, false);
		if (isEnable) {
			ContentValues values = new ContentValues();
			values.put(AnimalColumns.ISENABLE.getName(), 1);
			getContentResolver().update(Animals.CONTENT_URI, values, null, null);
		}

		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {

				final Intent mainIntent = new Intent(SplashScreenActivity.this, HomeActivity.class);
				startActivity(mainIntent);
				finish();
			}
		}, SPLASH_DISPLAY_LENGTH);

	}

}
